#!/usr/bin/env python
#-*- coding: UTF-8 -*- 

import sys
import mysql.connector
from mysql.connector import errorcode
reload(sys)
sys.setdefaultencoding("utf8")

config = {
			"user":"zyl",
			"password":"zyl",
			"host":"192.168.131.62",
			"database":"zdc",
			"charset":"utf8",
		}

#cnx = mysql.connector.connect(user="zyl",password="zyl",host="192.168.131.62",database="zdc",charset="utf8")
cnx = mysql.connector.connect(**config)

cursor = cnx.cursor()

cursor.execute("select id,name,sex,department,post from staff")
result = cursor.fetchall()


f =file("/home/zyl/Yunio/临时文件/staff-old.txt","w")
for (id,name,sex,department,port) in result:
	print("%4d,%s,%s,%s,%s" %(id,name,sex,department,port))
	f.write("%4d,%s,%s,%s,%s" %(id,name,sex,department,port))
	f.write("\n")


f.close()
cursor.close()
cnx.close()
